<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script crossorigin="anonymous" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js"></script>

    <title>Document</title>
</head>

<body>
    <form id="myForm" name="myForm">
        <div>
            <label for="username">Enter name:</label>
            <input type="text" id="username" name="username">
        </div>
        <div>
            <label for="useracc">Enter account number:</label>
            <input type="text" id="useracc" name="useracc">
        </div>
        <div>
            <label for="userfile">Upload file:</label>
            <input type="file" id="userfile" name="userfile">
        </div>
        <input type="submit" value="Submit!">
    </form>
    <script>
        var token = localStorage.getItem('mytoken');
        var a = document.getElementById('userfile');
        a.addEventListener('change', function() {

                const myForm = document.getElementById('myForm')
                    // let files = $('#userfile').get(0).files[0]
                var formData = new FormData(myForm);
                // console.log(formData);
                let reader = new FileReader();
                reader.readAsDataURL(files)
                formData.append('re', files);
                var aa = formData.get('userfile')
                console.log(aa);
                // console.log(formData);

                $.ajax({
                    url: `http://192.168.3.184:7001/images`,
                    type: 'post',
                    headers: {
                        token
                        // : localStorage.getItem('mytoken')
                    },
                    contentType: false,
                    processData: false,
                    success: (res) => {
                        console.log(res);

                    }

                })



            })
            // console.log();
    </script>
</body>

</html>